<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./node_modules/vue/dist/vue.js"></script>
  </head>

  <body>
    <div id="app">
      <button @click="showFoo">show foo</button>
      <!-- <Foo :visible="isShow" @close="handleClose"></Foo> -->
      <Foo v-model="isShow"></Foo>
    </div>
    <script>
      // emit -> output
      const Foo = {
        props: ["visible"],
        // props: ["value"],
        model: {
          prop: "visible",
          event: "close",
        },
        template: `<div v-show="visible">
          Foo
          <button @click="handleClose">X</button>
          </div>`,
        methods: {
          handleClose() {
            // 去修改 props 的值得
            // v-model -> input
            this.$emit("close", false);
            // this.$emit("input", false);
          },
        },
      };

      const app = new Vue({
        el: "#app",
        components: {
          Foo,
        },
        data: {
          isShow: false,
        },
        methods: {
          showFoo() {
            this.isShow = true;
          },
          handleClose() {
            this.isShow = false;
          },
        },
      });
    </script>
  </body>
</html>
